package cz.semjob.document.processing;

import java.util.ArrayList;
import java.util.List;


public class DocumentSentence implements IIndexedPart {
	
	private int paragraphIndex;
	
	private int paragraphStartIndex;
	
	private DocumentInstance document;
	
	private List<DocumentWord> words;
	
	private String text;
	
	public DocumentSentence(DocumentInstance document) {
		super();
		this.words = new ArrayList<DocumentWord>();
		this.document = document;
	}
	
	public void addWord(DocumentWord word) {
		words.add(word);
	}
	
	public List<DocumentWord> getWords() {
		return words;
	}

	public void setWords(List<DocumentWord> words) {
		this.words = words;
	}
	
	public int getDocumentIndex() {
		return document.getSentences().indexOf(this);
	}
	
	public int getWordsCount() {
		return words.size();
	}
	
	public int getCharacterCount() {
		return this.getEndIndex() - this.getStartIndex();
	}


	public int getStartIndex() {
		return words.get(0).getStartIndex();
	}

	public int getEndIndex() {
		return words.get(words.size()-1).getEndIndex();
	}


//	public void setIndexes(int startIndex, int endIndex) {
//		this.startIndex = startIndex;
//		this.endIndex = endIndex;
//	}

	public int getParagraphStartIndex() {
		return paragraphStartIndex;
	}

	public void setParagraphStartIndex(int paragraphStartIndex) {
		this.paragraphStartIndex = paragraphStartIndex;
	}

	public int getParagraphIndex() {
		return paragraphIndex;
	}

	public void setParagraphIndex(int paragraphIndex) {
		this.paragraphIndex = paragraphIndex;
	}

	public DocumentInstance getDocument() {
		return document;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	@Override
	public String toString() {
		return "DocumentSentence [words=" + words + ", startIndex="
				+ getStartIndex() + ", endIndex=" + getEndIndex() + "]";
	}

	public List<DocumentWord> getWordsByIndexes(int startIndex, int endIndex) {
		List<DocumentWord> documentWords =  new ArrayList<DocumentWord>();
		for (DocumentWord word : words) {
			if(word.getStartIndex()>=startIndex && word.getEndIndex() <= endIndex) {
				documentWords.add(word);
			}
		} 
		return documentWords;
	}
	
	public DocumentWord getWord(int index) {
		return words.get(index);
	}

}
